import React, {Component} from 'react'
import {View, Text, Dimensions, Animated, FlatList} from 'react-native'
import ChaptersIndex from './chapters'
import ChaptersIndex2 from './chapters2'
import BookList from './books'
//import Ranking from './ranking'
import StaticsIndex from '../statics/index'
import {connect} from 'react-redux'
import Enumeration from '../../config/enumeration'
import {StackNavigator, TabNavigator} from 'react-navigation'
import StudentStaticIndex from '../statics/student_static_index'
import ClassStaticsIndex from '../statics/class_statics_index'
import {BLUE} from '../../config/styles'


const StaticTabber = TabNavigator({
    tab1: {
        screen: ClassStaticsIndex,
        navigationOptions:{
            tabBarLabel: '班级统计',
        }

    },

    tab2: {
        screen: StudentStaticIndex,
        navigationOptions:{
            tabBarLabel: '学生统计',
        }
    }
},{
    tabBarPosition: 'top',
    animationEnabled: true,
    ...TabNavigator.Presets.AndroidTopTabs,
    tabBarOptions: {
        tabStyle:{
            alignItems: 'center',
            justifyContent: 'flex-start',
        },
        labelStyle: {
            color:'black',
            fontSize: 14
        },
        activeTintColor: BLUE,
        style:{
            backgroundColor:'#fff'
        },
        indicatorStyle: {
            backgroundColor: "#333"
        },
        indicatorStyle:{
            backgroundColor:BLUE
        }
    },

})

//这个组件主要是判断一下权限，学生是chapters, 老师直接ranking
class SelfLearningIndex extends Component {
    static navigationOptions = ({ navigation }) => {
        let role = navigation.state.params && navigation.state.params.role
        if (navigation.state.params == undefined) {navigation.state.params = {}}
        let options = {
            title: role == Enumeration.User.Role.Student ? '自学乐园' : '自学榜单',
            //headerRight: <View />            
        }
        //if (role == Enumeration.User.Role.Student) {options.header = null}
        return options
       
    }

    componentDidMount () {
        const role = this.props.user.user.role
        this.props.navigation.setParams({role: role})                    
    }

    render () {
        const role = this.props.user.user.role
        return(
            role == Enumeration.User.Role.Student ? <BookList {...this.props} /> : <StaticTabber />
        )
    }
}

const mapStateToProps = (state) => {
    return {
        user: state.user
    }
}

export default connect(mapStateToProps)(SelfLearningIndex)